package visitor

import "fmt"

type ProductVisitor struct {
	products map[string]int
}

func NewProductVisitor() ISaleOrderVisitor {
	return &ProductVisitor{
		products: make(map[string]int,0),
	}
}

func (me *ProductVisitor) Visit(it *SaleOrder) {
	n,ok := me.products[it.Product]
	if ok {
		me.products[it.Product] = n + it.Quantity
	} else {
		me.products[it.Product] = it.Quantity
	}
}

func (me *ProductVisitor) Report() {
	for k,v := range me.products {
		fmt.Printf("product=%s, sum=%v\n", k, v)
	}
}
